<template>
	<NavBar icon="left" title="我的地址" />
	<view class="h-screen bg-[#f2f2f2] p-2 ">
		<AddressCard v-for="info in list" :info="info" @del="del" />
		<navigator url="/pages/admin/address/address_edit/address_edit">
			<uv-button type="primary" text="添加地址" customStyle="margin-top: 10px" ></uv-button>
		</navigator>
	</view>
	<uv-modal ref="modal" showCancelButton content='确认要删除该条地址吗？' @confirm="confirm"></uv-modal>
</template>

<script setup>
	import * as api from '@/api/modules/address.js'
	import store from '@/store'
	const list = ref([])
	// 查询地址
	const user = store().user
	const getAddressList = async () => {
		const {
			data
		} = await api.addressInfoListAPI(user.userInfo.userId)
		list.value = data
	}
	getAddressList() 
	// 删除
	const modal = ref()
	let addressId = ''
	const del = id => {
		addressId = id
		modal.value.open()
	}
	const confirm = async () => {
		await api.delAddressAPI(addressId)
		await  getAddressList()
		uni.showToast({
			title: '删除地址成功',
			icon: 'none'
		})
	}
</script>

<style lang="scss">

</style>